package com.ftg.learn.chapter12.springbootdemo.controller;

import com.ftg.learn.chapter12.springbootdemo.entity.TeachersEntity;
import com.ftg.learn.chapter12.springbootdemo.service.TeacherService;
import com.ftg.learn.chapter12.springbootdemo.util.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 布衣
 */
@RestController
@Api(tags = "测试")
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    /**
     * GetMapping  表示当前方法 ，要通过get方式访问,在地址栏直接输入访问地址
     * postMapping : 添加 ，特殊的查询
     * putMapping :  修改
     * deleteMapping : 删除
     * 查询 方法
     *
     * @return
     */
    @GetMapping("/list")
    public R<List<TeachersEntity>> list() {
        return R.success(teacherService.list());
    }

    @PostMapping("/save")
    public R<String> abc(TeachersEntity t) {
        return teacherService.save(t);
    }

    @DeleteMapping("/del/{id}")
    public R<String> delById(@PathVariable("id") Integer id) {
        return teacherService.delById(id);
    }
}
